package edu.scau.web.core;

import edu.scau.core.constants.AjaxResult;
import edu.scau.core.exection.BusinessProcessException;
import edu.scau.finance.order.mapper.OrderReportMapper;
import edu.scau.pos.refund.mapper.RefundRecordMapper;
import edu.scau.pos.vo.RefundOrderVo;
import edu.scau.pos.vo.SaleItemVo;
import edu.scau.pos.vo.SaleLineItemVo;
import edu.scau.pos.vo.SaleVo;
import edu.scau.sku.domain.SkuRecord;
import edu.scau.sku.mapper.SkuRecordMapper;
import edu.scau.sku.service.SkuRecordService;
import edu.scau.system.service.UserAuthServiceImpl;
import edu.scau.tool.domain.FileInfo;
import edu.scau.tool.sevice.FileService;
import io.swagger.v3.oas.annotations.Hidden;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private SkuRecordService skuRecordService;
    @Autowired
    private OrderReportMapper orderReportMapper;
    @Autowired
    private FileService fileService;
    @GetMapping("/")
    public String index(){
        return "Hello MISP";
    }



    @PreAuthorize("hasAuthority('admin')")
    @GetMapping("/test1")
    @Hidden
    public String test1(){
        return "授权【管理员】访问";
    }


    @PreAuthorize("hasAuthority('cashier')")
    @GetMapping("/test2")
    @Hidden
    public String test2(){
        return "授权【收银员】访问";
    }

    @PostMapping("/validate")
    public AjaxResult validate(@Validated  @RequestBody SaleLineItemVo refundOrderVo) {
        return AjaxResult.success();
    }

    @PostMapping("/insert")
    public AjaxResult insert(@Validated @RequestBody SkuRecord skuRecord) {
        return AjaxResult.success(skuRecordService.insert(skuRecord));
    }

    @GetMapping("/refund")
    @Hidden
    public AjaxResult li(Date startTime, Date endTime){
//        return AjaxResult.success(orderReportMapper.calculateAmountGroupByCategory(startTime,endTime));
        return AjaxResult.success();
    }

    /**
     * 以流的形式上传图片
     *
     * @param file
     * @return 返回访问路径
     */
    @PostMapping("upload")
    @Hidden
    public AjaxResult uploadFile(@RequestParam(value = "file") MultipartFile file)  {
        FileInfo fileInfo = fileService.uploadFile(file);
        return AjaxResult.success(fileInfo);
    }
}
